Public Class ZOrderFeature
    Inherits System.Windows.Forms.Form

    Private ptrFeatures As ArrayList

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents lstFeatures As System.Windows.Forms.ListBox
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents btnMoveDown As System.Windows.Forms.Button
    Friend WithEvents btnMoveUp As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(ZOrderFeature))
        Me.lstFeatures = New System.Windows.Forms.ListBox()
        Me.btnMoveDown = New System.Windows.Forms.Button()
        Me.btnMoveUp = New System.Windows.Forms.Button()
        Me.btnOK = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'lstFeatures
        '
        Me.lstFeatures.Location = New System.Drawing.Point(8, 8)
        Me.lstFeatures.Name = "lstFeatures"
        Me.lstFeatures.Size = New System.Drawing.Size(184, 238)
        Me.lstFeatures.TabIndex = 0
        '
        'btnMoveDown
        '
        Me.btnMoveDown.Image = CType(resources.GetObject("btnMoveDown.Image"), System.Drawing.Bitmap)
        Me.btnMoveDown.Location = New System.Drawing.Point(192, 112)
        Me.btnMoveDown.Name = "btnMoveDown"
        Me.btnMoveDown.Size = New System.Drawing.Size(24, 24)
        Me.btnMoveDown.TabIndex = 1
        '
        'btnMoveUp
        '
        Me.btnMoveUp.Image = CType(resources.GetObject("btnMoveUp.Image"), System.Drawing.Bitmap)
        Me.btnMoveUp.Location = New System.Drawing.Point(192, 88)
        Me.btnMoveUp.Name = "btnMoveUp"
        Me.btnMoveUp.Size = New System.Drawing.Size(24, 24)
        Me.btnMoveUp.TabIndex = 2
        '
        'btnOK
        '
        Me.btnOK.Location = New System.Drawing.Point(112, 256)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 3
        Me.btnOK.Text = "OK"
        '
        'ZOrderFeature
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(226, 288)
        Me.ControlBox = False
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnOK, Me.btnMoveUp, Me.btnMoveDown, Me.lstFeatures})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Name = "ZOrderFeature"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Z Order"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public Sub ShowForm(ByRef feats As ArrayList)

        ptrFeatures = feats

        If ptrFeatures.Count = 0 Then Exit Sub

        ' populate the list
        PopulateList()

        Me.ShowDialog()
    End Sub

    Private Sub PopulateList()
        Dim i As Int16
        Dim c As Int16

        lstFeatures.Items.Clear()
        c = ptrFeatures.Count - 1


        For i = 0 To c
            Try
                lstFeatures.Items.Add(ptrFeatures.Item(i))
            Catch ex As Exception

            End Try
        Next
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.Hide()
    End Sub

    Private Sub btnMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveUp.Click
        If lstFeatures.SelectedItem Is Nothing Then Exit Sub
        If lstFeatures.SelectedIndex = 0 Then Exit Sub

        ' swap the selected item with the above item
        Dim feat1 As Feature
        Dim feat2 As Feature

        Dim index1 As Int16 = lstFeatures.SelectedIndex
        Dim index2 As Int16 = index1 - 1

        feat1 = lstFeatures.SelectedItem
        feat2 = ptrFeatures.Item(index2)

        ptrFeatures.Item(index2) = feat1
        ptrFeatures.Item(index1) = feat2

        ' repopulate the list
        PopulateList()

        ' set the selected item
        lstFeatures.SelectedIndex = index2
    End Sub

    Private Sub btnMoveDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveDown.Click
        If lstFeatures.SelectedItem Is Nothing Then Exit Sub
        If lstFeatures.SelectedIndex = lstFeatures.Items.Count - 1 Then Exit Sub

        ' swap the selected item with the below item
        Dim feat1 As Feature
        Dim feat2 As Feature
        Dim index1 As Int16 = lstFeatures.SelectedIndex
        Dim index2 As Int16 = index1 + 1

        feat1 = lstFeatures.SelectedItem
        feat2 = ptrFeatures.Item(index2)

        ptrFeatures.Item(index2) = feat1
        ptrFeatures.Item(index1) = feat2

        ' repopulate the list
        PopulateList()
        ' set the selected index
        lstFeatures.SelectedIndex = index2
    End Sub

End Class
